Calculate the factorial of a numberΒΆ
Write a python function to calculate the factorial
of a number (a non-negative integer).
The function accepts the number as an argument.
def factorial(N):
if N == 0:
return 1
else:
return N * factorial(N - 1)
# test
n = int(input("Input a number to compute the factiorial : "))
print(factorial(n))
Output:
Input a number to compute the factiorial : 4
24